home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / image.ed / event7.c < prev    next >
C/C++ Source or Header  |  1985-10-26  |  38KB  |  1,071 lines

  1.                                
  2. /************* Event7.c ******************/
  3. #include "intuall.h"
  4. #include "imageedit.h"
  5. #include "my.dos.defines.h"
  6. #include "saveformat.h"
  7.  
  8. #define SLIDERGADGETS 0x64
  9.  
  10.  
  11.  
  12. #define MODIFYRED 0
  13. #define MODIFYGREEN 1
  14. #define MODIFYBLUE 2
  15.  
  16. #define TXHEIGHT80 8
  17. #define TXHEIGHT60 9
  18.         /* topaz.font height 9 is the 60 column text font in system */
  19.         /* topaz.font height 8 is the 80 column font */
  20.  
  21. SHORT txfont;   /* if 80, use topaz 80, if 60 use topaz 60 */
  22. SHORT txmode;   /* if 1, use jam1, if 2, use jam2 */
  23. SHORT settxcolor;
  24. struct TextAttr modfontattr;    /* font structure which I use, aside
  25.                                  * from intuition's use
  26.                                  */
  27. struct TextFont *myfontptr;     /* my font pointer returned by openfont */
  28.  
  29. extern struct TextFont *OpenFont();
  30.  
  31. SHORT depth;            /* this may have to be moved somewhere else */
  32. extern struct ViewPort *vp;
  33. #define SETPRIMARY 1
  34. #define SETBACKGROUND 0
  35.  
  36.  
  37. SHORT color_being_modified;
  38.  
  39.  
  40.  
  41. extern struct BitMap smallbitmap;
  42. extern struct RastPort smallrastport;
  43. extern struct Gadget colorgadget[];
  44. extern struct MsgPort *timerport;
  45. extern struct IOStdReq *timermsg;
  46. struct MsgPort *animtimerport;
  47. struct IOStdReq *animtimermsg;
  48. extern struct MsgPort *CreatePort();
  49. extern struct IOStdReq *CreateStdIO();
  50.  
  51. #define SECONDS io_Actual
  52. #define MICROSECONDS io_Length
  53.  
  54. extern doclick();
  55. extern erase_edit();
  56. extern struct RastPort *rp;
  57. extern USHORT class;
  58. extern USHORT code;
  59. extern USHORT qualifier;
  60. extern struct Window *w;
  61. extern struct frame f[];
  62. extern SHORT selected;
  63. extern struct RastPort undorastport;
  64. extern USHORT mode;
  65. extern struct Requester myrequest; 
  66. extern struct Requester dosrequest;
  67. extern struct IntuiText dosreqtext[];
  68. extern struct IntuiText dostext[];
  69.  
  70. extern struct IntuiText ncrt[];
  71. extern struct Requester textrequest;
  72. extern BYTE dosname[];
  73. extern struct IntuiText textreqtext[];
  74. extern struct Gadget trg[];
  75. extern struct StringInfo textstringstuff;
  76. extern UBYTE textstring[];
  77.  
  78.  
  79. extern struct Requester newcolorrequest;
  80. extern struct PropInfo myslider[];
  81. extern struct PropInfo textslider;
  82.  
  83.  
  84. extern SHORT framewidth, frameheight;
  85. extern SHORT timeout,click;
  86.  
  87. extern SHORT palette[];
  88. extern struct Gadget ncp[];
  89. extern struct Image cri[];
  90. extern struct Requester newcolorrequest;
  91.  
  92. SHORT gadgetid;
  93. SHORT primarytextpen, secondarytextpen;
  94.  
  95. SHORT undo_code;        /* keep track of what done, so may undo correctly */
  96.  
  97. extern APTR address;
  98.  
  99. BYTE *errorstring;
  100. #define NUMBER_OF_FRAMES 9      /* temporary limit */
  101.  
  102.  
  103. #define MOVELEFT 0
  104. #define MOVERIGHT 1
  105. #define MOVEUP 2
  106. #define MOVEDOWN 3
  107. #define MOVEEND 4
  108.  
  109. /* *********************undo codes ************************ */
  110. #define FRAME_CLEAR 1
  111. #define COPY_FROM 2
  112. #define MOVEIT 3
  113. #define MERGE_WITH 4
  114. #define SNAPSHOT 5
  115. #define ANIMATE 6
  116.  
  117. NoEvent() { code = -1; class = -1; qualifier = -1; return(0); }
  118.  
  119. SHORT testcode;
  120. SHORT savemode;         /* TRUE for save, FALSE for load */
  121.  
  122. HandleEvent()
  123. {
  124.         testcode = TRUE;        /* closewindow test for neil */
  125.     anotherpass:
  126.         switch(class)
  127.                 {
  128.                 case CLOSEWINDOW:
  129.                         return(FALSE);
  130.                         break;  
  131.                 case MOUSEBUTTONS:
  132.                         if ( code == IECODE_LBUTTON )
  133.                                         doclick(w->MouseX,w->MouseY);
  134.                         break;
  135.                 case GADGETUP:
  136.                         gadgetid = ((struct Gadget *)address)->GadgetID;
  137.                         if( gadgetid == DISKRWGADGETS)  /* cancel */ 
  138.                                 {       
  139.                                 NoEvent();
  140.                                 break;
  141.                                 }
  142.                         if( gadgetid == TEXTWRITEGADGETS) /* do write */ 
  143.                                 {
  144.                                 textwrite();    
  145.                                 NoEvent();
  146.                                 break;
  147.                                 }
  148.                         if( gadgetid == TEXTWRITEGADGETS+3) /* do mode */ 
  149.                                 {
  150.                                 textmode();     
  151.                                 NoEvent();
  152.                                 break;
  153.                                 }
  154.                         if( gadgetid == TEXTWRITEGADGETS+2) /* do style */ 
  155.                                 {
  156.                                 textstyle();
  157.                                 NoEvent();
  158.                                 break;
  159.                                 }
  160.                         /* (+1 is cancel, +4 is proportional, ignore till
  161.                          * the write command actually occurs 
  162.                          */
  163.                         else if( gadgetid == DISKRWGADGETS+1)   /* load or  
  164.                                                                  * save */
  165.                                 {       
  166.                                 performdiskstuff();
  167.                                 NoEvent();
  168.                                 break;
  169.                                 }
  170.                         else
  171.                                 {
  172.                                 NoEvent();
  173.                                 break;
  174.                                 }
  175.                         NoEvent();
  176.                         break;
  177.                 case GADGETDOWN:
  178.                         gadgetid = ((struct Gadget *)address)->GadgetID;
  179.                         
  180.                         if( gadgetid >= MOVEGADGETS && 
  181.                             gadgetid <= (MOVEGADGETS+4) )
  182.                                 {       
  183.                                 moveit(gadgetid);
  184.                                 NoEvent();
  185.                                 break;
  186.                                 }
  187.                         else if( gadgetid >= COLORGADGETS && 
  188.                                  gadgetid <= COLORGADGETS+31) 
  189.                                 {       
  190.                                 resetcolor(gadgetid-COLORGADGETS);
  191.                                 NoEvent();
  192.                                 break;
  193.                                 }
  194.                         else if( gadgetid >= TEXTCOLORGADGETS && 
  195.                                  gadgetid <= TEXTCOLORGADGETS+31)
  196.                                 {       
  197.                                 textcolorfix(gadgetid);
  198.                                 NoEvent();
  199.                                 break;
  200.                                 }
  201.                         else if( gadgetid >= SLIDERGADGETS && 
  202.                                  gadgetid <= SLIDERGADGETS+2)
  203.                                 {       
  204.                                 syscolorfix(gadgetid - SLIDERGADGETS);
  205.                                 goto anotherpass;
  206.                                         /* while in syscolorfix, we will
  207.                                          * read events from Intuition.
  208.                                          * Cannot do NoEvent() here since
  209.                                          * we have, within the HandleEvent
  210.                                          * routine itself, have trapped a
  211.                                          * message which must be handled.
  212.                                          * Therefore make "anotherpass" at
  213.                                          * the message handling, since the
  214.                                          * user stopped playing with the
  215.                                          * original color-change gadget
  216.                                          * and has either selected a new
  217.                                          * color change or a different
  218.                                          * gadget entirely 
  219.                                          */
  220.                                 break;
  221.                                 }
  222.                         else
  223.                                 {
  224.                                 NoEvent();
  225.                                 break;
  226.                                 }       
  227.                         NoEvent();
  228.                         break;
  229.                 case MENUPICK:
  230.                   mode = ITEMNUM(code); /* decode the command */
  231.                   switch (MENUNUM(code)) { 
  232.                         case 0:                                 /* color */
  233.                                 if ( ITEMNUM(code) == palette[DEPTH-1])
  234.                                         {
  235.                                         changecolor();
  236.                                         NoEvent();
  237.                                         break;
  238.                                         }
  239.                                 else
  240.                                         {
  241.                                         SetAPen( rp, ITEMNUM(code) );  
  242.                                         NoEvent();
  243.                                         break;
  244.                                         }
  245.                         case 1:                                 /* copy */
  246.                                 switch( ITEMNUM(code)) {
  247.                                         case 0:                 /* undo */
  248.                                                 undo();
  249.                                                 NoEvent();
  250.                                                 break;
  251.                                         case 1:                 /* scroll */
  252.                                                 snapshot();
  253.                                                 NoEvent();
  254.                                                 break;
  255.                                         case 2:               /* from-frame */
  256.                                                 copyfrom();
  257.                                                 NoEvent();
  258.                                                 break;
  259.                                         case 3:                 /* merge */
  260.                                                 mergewith();
  261.                                         default:
  262.                                                 NoEvent();
  263.                                                 break;
  264.                                         }
  265.                                 break;
  266.  
  267.                         case 2:                                 /* move */
  268.                                 switch( ITEMNUM(code)) {
  269.                                         case 0:                 /* animate */
  270.                                                 animate();
  271.                                                 NoEvent();
  272.                                                 break;
  273.                                         case 1:                 /* in-frame */ 
  274.                                                 move();
  275.                                                 NoEvent();
  276.                                                 break;
  277.                                         case 2:                 /* exchange */
  278.                                                 exchange();
  279.                                         default:
  280.                                                 NoEvent();
  281.                                                 break;
  282.                                         }
  283.                                 break;
  284.  
  285.                         case 3:                                 /* text */
  286.                                 switch( ITEMNUM(code)) {
  287.                                         case 0:                 /* mode */
  288.                                                 textdraw();     /* requester */
  289.                                                 NoEvent();
  290.                                                 break;
  291.                                         case 1:                 /* style */ 
  292.                                                 textcolor();    /* requester */
  293.                                         default:
  294.                                                 NoEvent();
  295.                                                 break;
  296.                                         }
  297.                         case 4:                                 /* disk */
  298.                                 switch( ITEMNUM(code)) {
  299.                                         case 0:                 /* save */
  300.                                                 save();
  301.                                                 NoEvent();
  302.                                                 break;
  303.                                         case 1:                 /* load */
  304.                                                 load();
  305.                                                 NoEvent();
  306.                                                 break;
  307.                                         case 2:                 /* done */
  308.                                                 done();
  309.                                         default:
  310.                                                 NoEvent();
  311.                                                 break;
  312.                                         }
  313.                         case 5:                                 /* misc */
  314.                                 switch( ITEMNUM(code)) {
  315.                                         case 0:                 /* clear */
  316.                                                 help();
  317.                                                 NoEvent();
  318.                                                 break;
  319.                                         case 1:                 /* help */
  320.                                                 clear();
  321.                                                 NoEvent();
  322.                                                 break;
  323.                                         case 2:                 /* scroll */
  324.                                                 scroll();
  325.                                                 NoEvent();
  326.                                                 break;
  327.                                         case 3:                 /* reconfig */
  328.                                                 reconfigure();
  329.                                                 NoEvent();
  330.                                                 break;
  331.                                         case 4:                 /* reconfig */
  332.                                                 leave();
  333.                                         default:
  334.                                                 NoEvent();
  335.                                                 break;
  336.                                         }
  337.                         default:
  338.                                 break;
  339.                         }
  340.                 default:
  341.                         break;
  342.                 }
  343.         return(testcode);
  344. }
  345.  
  346. leave(){                        /* later must provide an 'are you sure???' */ 
  347.         testcode = FALSE;
  348.         return(0);
  349.         }
  350.  
  351. changecolor()
  352. {
  353.         Request(&newcolorrequest,w);
  354.         return(0);
  355. }
  356.  
  357.  
  358. APTR oldaddress;
  359.  
  360. syscolorfix(whichpart)
  361. SHORT whichpart;
  362. {
  363.         SHORT r,g,b;
  364.         struct ColorMap *c;
  365.         SHORT currentcolor;
  366.         c = vp->ColorMap;
  367.  
  368.         currentcolor = GetRGB4(c,color_being_modified);
  369.         r = (currentcolor >> 8) & 0xf;
  370.         g = (currentcolor >> 4) & 0xf;
  371.         b = (currentcolor)      & 0xf;   
  372.  
  373.         oldaddress = address;
  374.  
  375.         while( waiting_for_different_gadget())
  376.                 {
  377.                 switch(whichpart) 
  378.                    {
  379.                    case MODIFYRED:
  380.                         SetRGB4(vp,color_being_modified,getvalue(),g,b);
  381.                         break;
  382.                    case MODIFYGREEN:
  383.                         SetRGB4(vp,color_being_modified,r,getvalue(),b);
  384.                         break;
  385.                    case MODIFYBLUE:
  386.                         SetRGB4(vp,color_being_modified,r,g,getvalue());        
  387.                         break;
  388.                    default:
  389.                         break;
  390.                    }
  391.                 }
  392.         return;
  393. }
  394.  
  395. getvalue()      /* address points to the proportional gadget which is down */
  396. {
  397.         struct PropInfo *p;
  398.         struct Gadget *g;
  399.         g = (struct Gadget *)address; 
  400.         p = (struct PropInfo *)(g->SpecialInfo);
  401.         return( (p->HorizPot & 0xf000) >> 12);  /* read the pot value and
  402.                                                  * return it for color 
  403.                                                  * modifications
  404.                                                  */
  405. }
  406.         
  407.  
  408.  
  409.  
  410.  
  411. resetcolor(id)
  412. SHORT id;
  413.                 /* make the sliders jump out to the RGB values for the
  414.                  * color that was selected.  In a different loop, 
  415.                  * watch the value of the sliders and do a SetRGB4
  416.                  * with the values found until requester goes away
  417.                  */
  418. {
  419.         USHORT rpercent, gpercent, bpercent;
  420.         struct ColorMap *c;
  421.  
  422.         color_being_modified = id;
  423.  
  424.         EndRequest(&newcolorrequest,w);
  425.                 /* get rid of the requester to stop multi-flash when
  426.                  * modify prop is done 
  427.                  */
  428.  
  429.   /* change the color of the box at the top of the requester */
  430.  
  431.         cri[palette[ DEPTH - 1]].PlaneOnOff = id & 0x1f;
  432.  
  433.         c = vp->ColorMap;
  434. /* ******************************************* out temporarily 
  435.         ModifyProp(&colorgadget[0],w,&newcolorrequest,FREEHORIZ,
  436.                          (GetRGB4(c,id) <<4) &0xf000,   0,0,0);
  437.         ModifyProp(&colorgadget[1],w,&newcolorrequest,FREEHORIZ,
  438.                          (GetRGB4(c,id) <<8) &0xf000,   0,0,0);
  439.         ModifyProp(&colorgadget[2],w,&newcolorrequest,FREEHORIZ,
  440.                          (GetRGB4(c,id) <<12) &0xf000,  0,0,0);
  441. ************************************************************************ */
  442.                 /* prop gadget to modify, pointer to window, pointer to req, 
  443.                         flags, new horizontal, new vertical, hbody, vbody */
  444.  
  445.         myslider[0].HorizPot = 0x1111 * ((GetRGB4(c,id) >> 8) & 0xf);
  446.                         /* convert 4 bits into 16 bits by
  447.                          * replicating it in all 4 positions
  448.                          */
  449.         myslider[1].HorizPot = 0x1111 * ((GetRGB4(c,id) >> 4) & 0xf);
  450.         myslider[2].HorizPot = 0x1111 * ((GetRGB4(c,id)     ) & 0xf);
  451.         /* got new colors, can now redraw the requester */
  452.  
  453.         Request(&newcolorrequest,w);    
  454.  
  455.  
  456. /* out 
  457.         RefreshGadgets(&colorgadget[0],w,&newcolorrequest); 
  458. */
  459.  
  460.         return(0);
  461. }
  462.  
  463.  
  464. reconfigure(){  return(0);}
  465.  
  466. textwrite()
  467. {
  468.         LONG temp1, temp2;
  469.         SHORT error;
  470.         SHORT length,length2;
  471.         UBYTE *s;
  472.         struct Font *oldfontsave;
  473.         temp1 = ((textslider.HorizPot >> 8) * (framewidth)) >> 8;
  474.         temp2 = ((textslider.VertPot >> 8) * (frameheight-7)) >> 8;
  475.  
  476.         Move(rp,f[selected].xmin + temp1, f[selected].ymin+6+temp2);
  477.         length = (framewidth - temp1)/10;       /* how many characters fit */   
  478.         if (length <= 0) return(0);
  479.         s = &textstring[0];
  480.         length2 = 0;
  481.         while(*s++ != '\0') length2++;
  482.         length = (length > length2 ? length2 : length);
  483.                 /* draw only as much text as will fit and no more */
  484.         if(txmode == 1)
  485.                 SetDrMd(rp,JAM1);
  486.         else
  487.                 SetDrMd(rp,JAM2);
  488.  
  489.         if(txfont == 80)
  490.                 modfontattr.ta_YSize = TXHEIGHT80;
  491.         else
  492.                 modfontattr.ta_YSize = TXHEIGHT60;
  493.         oldfontsave = rp->Font;         /* save current intuition font */
  494.         myfontptr = OpenFont(&modfontattr);     /* select what user asks */
  495.         if(myfontptr == 0) {
  496.                 printf("\font wont open");
  497.                 return(0);      
  498.                 }       /* dont draw text if font not found */
  499.         SetFont(rp,myfontptr);
  500. /*      if (error != 0) {
  501.                 printf("\nSetFont didnt");
  502.                 return(0);
  503.                 }
  504. */
  505.                 /* dont draw text if font is bad */
  506.         Text(rp,&textstring[0],length);
  507.         SetFont(rp,oldfontsave);        /* restore old font */
  508.         CloseFont(myfontptr);   
  509.         return(0);
  510. }
  511.  
  512.         
  513. textdraw()
  514. {
  515.         Request(&textrequest,w);
  516.         return(0);
  517. }
  518.  
  519. textstyle()
  520. {
  521.         if( trg[1].GadgetText == &textreqtext[7])
  522.                 {
  523.                 trg[1].GadgetText = &textreqtext[8];
  524.                 txmode = 2;
  525.                 }
  526.         else if(trg[1].GadgetText == &textreqtext[8])
  527.                 {
  528.                 trg[1].GadgetText = &textreqtext[7];
  529.                 txmode = 1;
  530.                 }
  531.         RefreshGadgets(&trg[1],w,&textrequest);
  532. }
  533.  
  534. textmode()
  535. {
  536.         if( trg[2].GadgetText == &textreqtext[9])
  537.                 {
  538.                 trg[2].GadgetText = &textreqtext[10];
  539.                 txfont = 60;
  540.                 }
  541.         else if(trg[2].GadgetText == &textreqtext[10])
  542.                 {
  543.                 trg[2].GadgetText = &textreqtext[9];
  544.                 txfont = 80;
  545.                 }
  546.         RefreshGadgets(&trg[1],w,&textrequest);
  547. }
  548.  
  549. textcolorfix(id)
  550. SHORT id;
  551. {
  552.         if( settxcolor == SETPRIMARY )
  553.                 primarytextpen = id - TEXTCOLORGADGETS;
  554.         else
  555.                 secondarytextpen = id - TEXTCOLORGADGETS;       
  556.         return(0);
  557. }
  558.  
  559. textcolor(){return(0);} /* brings up a requester only */
  560. scroll(){return(0);}
  561.  
  562. init_animtimer()
  563. {
  564.         return(OpenDevice(TIMERNAME,UNIT_VBLANK,animtimermsg,0));
  565. }
  566.  
  567. set_animtimer(sec,micro)
  568. ULONG sec,micro;
  569. {
  570.         animtimermsg->io_Command = TR_ADDREQUEST;
  571.                                         /* add a new timer request */
  572.         animtimermsg->SECONDS = sec;    /* seconds */
  573.         animtimermsg->MICROSECONDS = micro; /* microseconds */
  574.         SendIO( animtimermsg );         /* post a request to the timer */
  575.         return(0);
  576. }
  577.  
  578.  
  579. animate()
  580. {
  581.         SHORT n;
  582.         SHORT currentselect;    /* just for faking out the undo code */
  583.         undo_code = ANIMATE;
  584.         save_in_undo(0);
  585.  
  586.         animtimerport = CreatePort(0,0);
  587.         animtimermsg = CreateStdIO(animtimerport);
  588.         init_animtimer();
  589.  
  590.         for(n=0; n<9; n++)
  591.                 {
  592.                 ClipBlit(rp,            /* source rastport */
  593.                 f[n].xmin,      /* source location x and y */
  594.                 f[n].ymin,
  595.                 rp,             /* destination rastport */
  596.                 f[0].xmin, 
  597.                 f[0].ymin,
  598.                 framewidth,     /* bit-size of rectangle */
  599.                 frameheight,
  600.                 0xc0);          /* c0 means bit-for bit in all planes */
  601.         
  602.                 set_animtimer(0,333333);  /* 1/3 second between animates */
  603.                 Wait( 1 << animtimerport->mp_SigBit); /* wait for timeout */
  604.                 GetMsg( animtimerport );  
  605.                                 /* remove the message after the wait */
  606.   
  607.                 } 
  608.  
  609.         currentselect = selected;
  610.         selected = 0;           /* not really selected, just for undo
  611.                                  * so that frame 0 is restored to screen 
  612.                                  * at the end of the animation 
  613.                                  */
  614.         undo();   
  615.         selected = currentselect;
  616.  
  617.         CloseDevice(animtimermsg);
  618.         DeleteStdIO(animtimermsg);
  619.         DeletePort(animtimerport);
  620.  
  621.         return(0);
  622. }
  623.         
  624.  
  625. snapshot()
  626. {
  627. undo_code = SNAPSHOT;
  628. save_in_undo(selected);
  629. return(0);
  630. }
  631.  
  632. help(){return(0);}
  633. done(){return(0);}
  634.  
  635.                         /* only change to Event.c ... activate save request */
  636. save()
  637. {
  638.         dostext[1].IText = (UBYTE *)"SAVE";
  639.         Request(&dosrequest,w);
  640.         savemode = TRUE;
  641.         return(0);
  642. }
  643.  
  644. load()
  645. {
  646.         dostext[1].IText = (UBYTE *)"LOAD";
  647.         Request(&dosrequest,w);
  648.         savemode = FALSE;
  649.         return(0);
  650. }
  651.  
  652. performdiskstuff()
  653. {
  654.         if(savemode)    
  655.                 dodisksave();
  656.         else
  657.                 dodiskload();
  658.         return(0);
  659. }
  660.  
  661. dodisksave()
  662. {
  663.         UWORD n,i,j;
  664.         struct saveformat s;
  665.         ULONG length;
  666.         UBYTE *p;       /* pointer to data */   
  667.         /* first open the file for save ... if it exists, for now,
  668.          * refuse to do it.  (later bring up a requester that asks
  669.          * if you want to replace it) 
  670.          */
  671.  
  672.         s.next = 0;
  673.         s.depth = DEPTH;        /* system global variable */ 
  674.         s.width = framewidth;
  675.         s.height = frameheight;
  676.         s.colorset = sizeof(struct saveformat)-2; 
  677.                                                 /* store colors first */
  678.         s.dataset = s.colorset + ((palette[DEPTH-1])<<1);
  679.                         /* start data storage immediately after the colors */   
  680.                         /* each color listed in palette[depth-1] takes 2
  681.                          * bytes to store in the disk file */
  682.  
  683.         file = Open( &dosname[0], MODE_NEWFILE );
  684.         if (file == 0 ) 
  685.                         /* couldnt open as a new file */
  686.                 {
  687.                 errorstring = "\nFile Already Exists, Choose A New Name";
  688.                 printf(errorstring);
  689.                 return(0);
  690.                 }
  691.  
  692. printf("file open for save\n");
  693.         /* SAVE THE DATA DESCRIPTOR */
  694.  
  695.         length = sizeof(struct saveformat)-2;   
  696.                         /* how many bytes to write on first save */
  697.         
  698.         actual_len = Write( file, &s, length );
  699.         if (actual_len != length )
  700.                 goto write_error;
  701.                                         printf("saved the data descriptor\n");
  702.         /* SAVE THE COLOR PALETTE */
  703.  
  704.         length = (palette[DEPTH-1])<<1;         /* two bytes per word */
  705.         actual_len = Write( file, vp->ColorMap->ColorTable, length);
  706.         if(actual_len != length)
  707.                 goto write_error;
  708.                                         printf("saved the color palette\n");
  709.  
  710.         /* TEMPORARY LIMIT OF 9 frames */
  711.  
  712.  
  713.         length = ((framewidth+15)>>4)<<1;       /* calculate words,
  714.                                                  * save as bytes 
  715.                                                  * (dos writes bytes) */
  716.         for(n=0; n<NUMBER_OF_FRAMES; n++)
  717.                 {               /* copy to bit/word align in small rastport */
  718.                 ClipBlit(rp,            /* source rastport */
  719.                 f[n].xmin,      /* source location x and y */
  720.                 f[n].ymin,
  721.                 &smallrastport, /* small rastport destination rastport */
  722.                 0,              /* destination x and y */
  723.                 0,
  724.                 framewidth,     /* bit-size of rectangle */
  725.                 frameheight,
  726.                 0xc0);          /* c0 means bit-for bit in all planes */
  727.                 for(i=0; i<BOBDEPTH; i++)
  728.                         {
  729.                         p = smallbitmap.Planes[i];
  730.                         for(j=0; j<frameheight; j++)
  731.                                 {
  732.                                 actual_len = Write(file, p, length);                                            if(actual_len != length) goto write_error;
  733.                                 p += smallbitmap.BytesPerRow;
  734.                                 }
  735.                         }
  736.                                                 printf("saved one frame\n");
  737.                 }
  738.         Close(file);
  739.         return(0);
  740.    write_error:
  741.         Close (file);
  742.         errorstring = "Error While Trying To Write"; 
  743.  
  744.         /* bring up a requester to tell user about the error */
  745.                 /* FUTURE */
  746.         return(0); 
  747. }
  748.  
  749. dodiskload()
  750. {
  751.         UWORD n,i,j;
  752.         struct saveformat s;
  753.         ULONG length;
  754.         UWORD colorstoload[32];
  755.         UBYTE *p;       /* pointer to data */   
  756.         /* first open the file for load ... if it doesnt exist, for now,
  757.          * refuse to do it.  (later bring up a requester that asks
  758.          * for a different name) 
  759.          */
  760.         file = Open( &dosname[0], MODE_OLDFILE );
  761.         if (file == 0 ) 
  762.                         /* couldn't open the file */
  763.                 {
  764.                 errorstring = "\nFile Not Found Or Unknown Error";
  765.                 printf(errorstring);
  766.                 return(0);
  767.                 }
  768.  
  769. printf("opened for read\n");
  770.         /* READ THE SAVEFORMAT info */
  771.         length = (sizeof(struct saveformat)-2);
  772.         actual_len = Read( file, &s, length);
  773.         if (actual_len != length) goto read_error;
  774.  
  775.         /* first pass assumes everything is ok as to where data is going  */
  776.  
  777.                                              printf("read the load-format\n");
  778.         /* READ AND LOAD THE COLOR INFO */
  779.  
  780.         if( s.colorset != 0 )
  781.                 {       
  782.                 Seek( file, s.colorset, OFFSET_BEGINING);
  783.                         /* seek to where in the file the color set starts */    
  784.                 length = (palette[s.depth-1])<<1;
  785.                 actual_len = Read( file, &colorstoload[0], length);
  786.                 if (actual_len != length) goto read_error;
  787.                 LoadRGB4(vp, &colorstoload[0], palette[s.depth-1]);
  788.                 }
  789. printf("read and loaded the colors\n");
  790.         if( s.dataset != 0 )
  791.              {  
  792.                 Seek( file, s.dataset, OFFSET_BEGINING);
  793.                         /* seek to where in the file the color set starts */    
  794.                 length = ((framewidth+15)>>4)<<1;       
  795.                 for(n=0; n<NUMBER_OF_FRAMES; n++)
  796.                 {               /* copy to bit/word align in small rastport */
  797.                 for(i=0; i<BOBDEPTH; i++)
  798.                         {
  799.                         p = smallbitmap.Planes[i];
  800.                         for(j=0; j<frameheight; j++)
  801.                                 {
  802.                                 actual_len = Read(file, p, length);     
  803.                                 if(actual_len != length) goto read_error;
  804.                                 p += smallbitmap.BytesPerRow;
  805.                                 }
  806.                         }
  807.                 ClipBlit(&smallrastport, 
  808.                 0,              /* destination x and y */
  809.                 0,
  810.                 rp,            /* source rastport */
  811.                 f[n].xmin,      /* source location x and y */
  812.                 f[n].ymin,
  813.                 framewidth,     /* bit-size of rectangle */
  814.                 frameheight,
  815.                 0xc0);          /* c0 means bit-for bit in all planes */
  816. printf("read and loaded a frame\n");
  817.                 }
  818.                 Close(file);
  819.                 return(0);
  820.            }
  821.         read_error:
  822.                 errorstring = "Error While Trying To Read";
  823.                         /* bring up a requester to tell user about this */
  824.                 Close(file); 
  825.                 return(0);
  826. }       
  827.                 
  828.  
  829.  
  830.  
  831. save_in_undo(n)
  832.         SHORT n;
  833.         {
  834.         ClipBlit(rp,            /* source rastport */
  835.                 f[n].xmin,      /* source location x and y */
  836.                 f[n].ymin,
  837.                 &undorastport,  /* undo  rastport destination rastport */
  838.                 0,              /* destination x and y */
  839.                 0,
  840.                 framewidth,     /* bit-size of rectangle */
  841.                 frameheight,
  842.                 0xc0);          /* c0 means bit-for bit in all planes */
  843.         return(0);
  844.         }
  845.  
  846. move()                  /* just brings up a requester */
  847. {
  848.         Request( &myrequest, w); 
  849.         return(0);
  850. }
  851.  
  852.  
  853. moveit(where)
  854. SHORT where;
  855. {
  856.         switch(where) {
  857.                 case MOVELEFT:
  858.                         moveitsub(-1,0);
  859.                         break;
  860.                 case MOVERIGHT:
  861.                         moveitsub(1,0);
  862.                         break;
  863.                 case MOVEUP:
  864.                         moveitsub(0,-1);
  865.                         break;
  866.                 case MOVEDOWN:
  867.                         moveitsub(0,1);
  868.                         break;
  869.                 case MOVEEND:
  870.                         doexpand(selected);
  871.                         break;
  872.                 }
  873.         return(0);
  874. }
  875.  
  876.  
  877. moveitsub(x,y) 
  878. SHORT x,y;
  879. {
  880.                 /* move it a distance in the x and y direction */
  881.  
  882.         SHORT width, height;
  883.         SHORT xsrc, ysrc;
  884.         SHORT xdest, ydest;
  885.         SHORT oldpen;
  886.  
  887.         if( x == 0 )    
  888.                 {
  889.                 height = frameheight - 1;
  890.                 width = framewidth;
  891.                 xsrc = 0;
  892.                 xdest = f[selected].xmin;
  893.                 if( y < 0)
  894.                         {
  895.                         ydest = f[selected].ymin;       /* move up */ 
  896.                         ysrc  = 1; 
  897.                         }
  898.                 else
  899.                         {
  900.                         ydest = f[selected].ymin+1;   /* move down */
  901.                         ysrc = 0;
  902.                         }
  903.                 }
  904.  
  905.         if( y == 0 )    
  906.                 {
  907.                 height = frameheight;
  908.                 width = framewidth - 1;
  909.                 ysrc = 0;
  910.                 ydest = f[selected].ymin;
  911.                 if( x < 0)
  912.                         {
  913.                         xdest = f[selected].xmin;       /* move left */ 
  914.                         xsrc  = 1; 
  915.                         }
  916.                 else
  917.                         {
  918.                         xdest = f[selected].xmin+1;   /* move right */
  919.                         xsrc = 0;
  920.                         }
  921.                 }
  922.  
  923.         save_in_undo(selected);         /* save the selected one in undo */
  924.         undo_code = MOVEIT;
  925.         ClipBlit(&undorastport, /* undo = source rastport */
  926.                 xsrc,          /* source x and y */
  927.                 ysrc,
  928.                 rp,             /* undo  rastport destination rastport */
  929.                 xdest,          /* destination x and y */
  930.                 ydest,
  931.                 width,          /* bit-size of rectangle */
  932.                 height,
  933.                 0xc0);          /* c0 means bit-for bit in all planes */
  934.  
  935.         oldpen = rp->FgPen;
  936.         SetAPen(rp,0);          /* going to adjust edges after move */
  937.         if(x == 0)
  938.              switch(ysrc)
  939.                 {
  940.                 case 0: Move(rp,f[selected].xmin,f[selected].ymin);
  941.                         Draw(rp,f[selected].xmax,f[selected].ymin);
  942.                         break;
  943.                 case 1: Move(rp,f[selected].xmin,f[selected].ymax);
  944.                         Draw(rp,f[selected].xmax,f[selected].ymax);
  945.                         break;
  946.                 }
  947.         if(y == 0)
  948.              switch(xsrc)
  949.                 {
  950.                 case 0: Move(rp,f[selected].xmin,f[selected].ymin);
  951.                         Draw(rp,f[selected].xmin,f[selected].ymax);
  952.                         break;
  953.                 case 1: Move(rp,f[selected].xmax,f[selected].ymin);
  954.                         Draw(rp,f[selected].xmax,f[selected].ymax);
  955.                         break;
  956.                 }
  957.         SetAPen(rp,oldpen);
  958.         return(0);
  959. }
  960.  
  961.  
  962.  
  963. clear()         /* clear the selected window, but save the image in the
  964.                  * undo buffer so user can restore it if he wants to */
  965. {
  966.         SHORT n,oldpen;
  967.         undo_code = FRAME_CLEAR;
  968.         n = selected;           /* can only clear the selected frame */
  969.         save_in_undo(n);
  970.  
  971.         /* now clear it */
  972.  
  973.         oldpen = rp->FgPen;
  974.         SetAPen(rp, 0);
  975.         RectFill(rp, f[n].xmin, f[n].ymin, f[n].xmax, f[n].ymax );
  976.         SetAPen(rp,oldpen);
  977.         erase_edit();           /* selected one is displayed, so clear 
  978.                                  * there also */
  979.         return(0);
  980. }
  981.  
  982.  
  983. copyfrom()      /* copy from specified frame into selected frame */
  984.         {
  985.         SHORT n;
  986.         undo_code = COPY_FROM;
  987.         n = SUBNUM(code);
  988.         save_in_undo(selected);  /* save old contents */
  989.         
  990.         ClipBlit(rp,            /* source rastport */
  991.                 f[n].xmin,      /* source location x and y */
  992.                 f[n].ymin,
  993.                 rp,             /* destination rastport */
  994.                 f[selected].xmin, 
  995.                 f[selected].ymin,
  996.                 framewidth,     /* bit-size of rectangle */
  997.                 frameheight,
  998.                 0xc0);          /* c0 means bit-for bit in all planes */
  999.         doexpand(selected);
  1000.         return(0);
  1001.         }       
  1002.  
  1003. mergewith()     /* Merge data from specified into selected frame */
  1004.         {
  1005.         SHORT n;
  1006.         undo_code = MERGE_WITH;
  1007.         n = SUBNUM(code);
  1008.         save_in_undo(selected);  /* save old contents */
  1009.         
  1010.         ClipBlit(rp,            /* source rastport */
  1011.                 f[n].xmin,      /* source location x and y */
  1012.                 f[n].ymin,
  1013.                 rp,             /* destination rastport */
  1014.                 f[selected].xmin, 
  1015.                 f[selected].ymin,
  1016.                 framewidth,     /* bit-size of rectangle */
  1017.                 frameheight,
  1018.                 0xe0);          /* e0 means 'OR' the contents */
  1019.         doexpand(selected);
  1020.         return(0);
  1021.         }       
  1022.  
  1023.  
  1024.  
  1025. exchange()
  1026.         {
  1027.         SHORT n;
  1028.         n = SUBNUM(code);
  1029.         copyfrom();
  1030.         undo_code = 0;          /* to undo an exchange, simply exchange */
  1031.         ClipBlit(&undorastport, /* source rastport */
  1032.                 0,              /* source location x and y */
  1033.                 0,
  1034.                 rp,             /* destination rastport */
  1035.                 f[n].xmin,
  1036.                 f[n].ymin,
  1037.                 framewidth,     /* bit-size of rectangle */
  1038.                 frameheight,
  1039.                 0xc0);          /* c0 means bit-for bit in all planes */
  1040.         doexpand(selected);
  1041.         return(0);
  1042.         }        
  1043.  
  1044. undo()
  1045.         {
  1046.         switch(undo_code) {
  1047.                         case FRAME_CLEAR:
  1048.                         case COPY_FROM:
  1049.                         case MOVEIT:
  1050.                         case SNAPSHOT:
  1051.                         case MERGE_WITH:
  1052.                         case ANIMATE:
  1053.                                 ClipBlit(&undorastport, /* source rastport */
  1054.                                    0,           /* source location x and y */
  1055.                                    0,
  1056.                                    rp,             /* destination rastport */
  1057.                                    f[selected].xmin, 
  1058.                                    f[selected].ymin,
  1059.                                    framewidth,     /* bit-size of rectangle */
  1060.                                    frameheight,
  1061.                                    0xc0);          /* bit-for bit all planes */
  1062.                                 break;
  1063.                         default:
  1064.                                 break;
  1065.                         }
  1066.         doexpand(selected);
  1067.         return(0);
  1068.         }       
  1069.  
  1070.  
  1071.